package com.wenx.talk.nettychat;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class ChatServerApplication {

    @Autowired
    @Qualifier("bootstrap")
    private ServerBootstrap bootstrap;

    private Channel channel;

    public void start() {
        System.out.println("netty启动...");
        try {
            channel = bootstrap.bind(8888).sync().channel().closeFuture().sync().channel();
        } catch (InterruptedException e) {
            System.out.println("netty启动失败");
            e.printStackTrace();
        }
    }

    public void close() {
        channel.close();
        channel.parent().close();
    }

}
